<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 'delete', 'comSearch', 'quickSearch', 'columnDisplay' -->
        <TableHeader
            :buttons="['refresh', 'add', 'edit']"
            :quick-search-placeholder="t('Quick search placeholder', { fields: t('member.email') + '/' + t('member.mobile') })"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" />

        <!-- 表单 -->
        <PopupForm />
    </div>
</template>

<script setup lang="ts">
import { ref, provide } from 'vue'
import baTableClass from '/@/utils/baTable'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'

defineOptions({
    name: 'user/user',
})

const { t } = useI18n()
const tableRef = ref()
const baTable = new baTableClass(
    new baTableApi('/backend/user/'),
    {
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('Id'), prop: 'id', align: 'center', operator: '=', operatorPlaceholder: t('Id'), width: 70 },
            { label: t('member.mobile'), prop: 'mobile', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
            { label: t('member.email'), prop: 'email', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
            { label: t('member.head_img'), prop: 'head_img', align: 'center', render: 'image', operator: false },

            // {
            //     label: t('member.last_ip'),
            //     prop: 'last_ip',
            //     align: 'center',
            //     operator: 'LIKE',
            //     operatorPlaceholder: t('Fuzzy query'),
            //     render: 'tag',
            // },
            // {
            //     label: t('member.last_time'),
            //     prop: 'last_time',
            //     align: 'center',
            //     render: 'datetime',
            //     sortable: 'custom',
            //     operator: 'RANGE',
            //     width: 160,
            // },
            { label: t('Create time'), prop: 'ctime', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
            // {
            //     label: t('State'),
            //     prop: 'status',
            //     align: 'center',
            //     render: 'tag',
            //     custom: { disable: 'danger', enable: 'success' },
            //     replaceValue: { disable: t('Disable'), enable: t('Enable') },
            // },
            { label: t('State'), prop: 'status', align: 'center', width: '80', render: 'switch' },
            {
                label: t('Operate'),
                align: 'center',
                width: '100',
                render: 'buttons',
                buttons: defaultOptButtons(['edit',]), // 'delete'
                operator: false,
            },
        ],
        dblClickNotEditColumn: [undefined],
    },
    {
        defaultItems: {
            gender: 0,
            money: '0',
            score: '0',
            status: 'enable',
        },
    }
)

baTable.mount()
baTable.getLists()

provide('baTable', baTable)
</script>

<style scoped lang="scss"></style>
